package org.javahispano.javacup.tacticas_aceptadas.camigonz.org.icesoft.javacup;

import org.javahispano.javacup.modelo.JugadorDetalle;
import org.javahispano.javacup.modelo.Posicion;
import org.javahispano.javacup.modelo.SituacionPartido;

public class Player {
	// 0 - Keeper
	// 1 - Moving to position
	// 2 - Following enemy
	// 3 - Chasing ball
	// 4 - Defend enemy
	// 5 - Chase ball directly
	// 6 - Chase ball directly keeper
	// 7 - Align
	// 8 - Seek ball directly, wait for pass
	// 9 - Wait for luck
	// 10 - Following enemy after
	private int state;
	
	private Player[] p;

	private SituacionPartido sp;

	private JugadorDetalle detail;

	private Posicion pos;

	private Posicion ball;

	private double ballHeight;

	private Posicion movingTo;

	private int following;

	private int oldFollowing;

	private Posicion align;

	private boolean teamBall;

	private int index;

	public Player(Player[] p) {
		this.p = p;
	}

	public boolean analyze() {
		return true;
	}

	/**
	 * @return the state
	 */
	public int getState() {
		return state;
	}

	/**
	 * @param state
	 *            the state to set
	 */
	public void setState(int state) {
		if (this.state == 8) {
			int l = sp.puedenRematar().length;
			if (!teamBall && sp.puedenRematarRival().length == 0) {
				return;
			} else if (teamBall && (l == 0 || (l > 0 && sp.puedenRematar()[0] != index))) {
				return;
			}
		}
		this.state = state;
	}

	/**
	 * @return the sp
	 */
	public SituacionPartido getSp() {
		return sp;
	}

	/**
	 * @param sp
	 *            the sp to set
	 */
	public void setSp(SituacionPartido sp) {
		this.sp = sp;
	}

	/**
	 * @return the pos
	 */
	public Posicion getPos() {
		return pos;
	}

	/**
	 * @param pos
	 *            the pos to set
	 */
	public void setPos(Posicion pos) {
		this.pos = pos;
	}

	/**
	 * @return the ball
	 */
	public Posicion getBall() {
		return ball;
	}

	/**
	 * @param ball
	 *            the ball to set
	 */
	public void setBall(Posicion ball) {
		this.ball = ball;
	}

	/**
	 * @return the ballHeight
	 */
	public double getBallHeight() {
		return ballHeight;
	}

	/**
	 * @param ballHeight
	 *            the ballHeight to set
	 */
	public void setBallHeight(double ballHeight) {
		this.ballHeight = ballHeight;
	}

	/**
	 * @return the movingTo
	 */
	public Posicion getMovingTo() {
		return movingTo;
	}

	/**
	 * @param movingTo
	 *            the movingTo to set
	 */
	public void setMovingTo(Posicion movingTo) {
		this.movingTo = movingTo;
	}

	/**
	 * @return the following
	 */
	public int getFollowing() {
		return following;
	}

	/**
	 * @param following
	 *            the following to set
	 */
	public void setFollowing(int following) {
		if (this.following != following) {
			this.oldFollowing = this.following;
		}
		this.following = following;
	}

	/**
	 * @return the detail
	 */
	public JugadorDetalle getDetail() {
		return detail;
	}

	/**
	 * @param detail
	 *            the detail to set
	 */
	public void setDetail(JugadorDetalle detail) {
		this.detail = detail;
	}

	/**
	 * @return the align
	 */
	public Posicion getAlign() {
		return align;
	}

	/**
	 * @param align
	 *            the align to set
	 */
	public void setAlign(Posicion align) {
		this.align = align;
	}

	/**
	 * @return the oldFollowing
	 */
	public int getOldFollowing() {
		return oldFollowing;
	}

	/**
	 * @return the teamBall
	 */
	public boolean isTeamBall() {
		return teamBall;
	}

	/**
	 * @param teamBall
	 *            the teamBall to set
	 */
	public void setTeamBall(boolean teamBall) {
		this.teamBall = teamBall;
	}

	public void stopWaitPass(int newState) {
		this.state = newState;
	}

	public void stopWaitPass() {
		stopWaitPass(7);
	}

	/**
	 * @return the index
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * @param index
	 *            the index to set
	 */
	public void setIndex(int index) {
		this.index = index;
	}

	@Override
	public String toString() {
		String x = "[" + index + ": " + state;
		if (state == 2) {
			x += "(" + following + ")";
		}
		x += "]";
		return x;
	}

	
}
